/*
 * sqlhandle.h
 *
 *  Created on: Dec 9, 2010
 *      Author: khanton
 */

#ifndef SQLHANDLE_H_
#define SQLHANDLE_H_

#include "sqlpool.h"
#include "con_state.h"

class controllers_network;

class sqlhandle
{
	public:
		sqlhandle();
		virtual ~sqlhandle();

		void start(const std::string &_host, const std::string &_user, const std::string &_password, const std::string &_database);

		void close();

		bool create_controller_on_network(const con_state::controller_id _controller, std::string &_key);
		
		void delete_controller_from_network(const con_state::controller_id _controller);
		
		void dump_query(const std::string &_query);
		
		void set_controller_state(const con_state::controller_id _id, const con_state::status_packet_t &_con_state);

		bool get_queue_cmd(int &_command, con_state::controller_id &_id, int &_param);
		
		bool get_controller_program(const con_state::controller_id _id, std::string &_program);
		
		bool start_program_update(const con_state::controller_id _id);
		
		bool end_program_update(const con_state::controller_id _id, bool _success);  

	private:

		AsudConnectionPool *pool_;
};

#endif /* SQLHANDLE_H_ */
